<?php

namespace app\index\controller;

use app\CommonController;
use app\model\Article;
use app\service\ArticleService;

class Notice extends CommonController
{
    public function index()
    {

        if ($this->request->post()) {
            $noticeService = $this->app->make(ArticleService::class);
            $params["status"] = Article::ARTICLE_STATUS_ACTIVE;
            $params["category_id"] = 1;
            $list = $noticeService->getListWithOutCount($params, "*", ["categories"]);
            $content = $this->fetch("notice-ajax", ["list" => $list]);
            $this->result(["data" => $content]);
        } else {
            return $this->fetch("index");
        }
    }

    public function detail()
    {
        $noticeService = $this->app->make(ArticleService::class);
        $id = $this->request->param("id");
        if (!$id) {
            $this->error("系统错误");
        }
        $info = $noticeService->getOne(["id" => $id, "status" => Article::ARTICLE_STATUS_ACTIVE], "create_at,title,content");
        if (empty($info)) {
            $this->error("公告不存在");
        }
        $this->assign("info", $info);
        return $this->fetch("detail");
    }
}